package com.itheima.myscoket.test8;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class ServerDemo {
    public static void main(String[] args) throws IOException {
        //接收端口
        ServerSocket ss = new ServerSocket(10086);
        //将数据写到本地
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("day16_网络编程\\Server\\1.jpg"));
        //接收网络中的流
        Socket accept = ss.accept();
        //得到读取
        InputStream is = accept.getInputStream();
        //将网络中读取的数写出来,写到本地
        BufferedInputStream bis = new BufferedInputStream(is);
        int len;
        while ((len = bis.read())!=-1){
            bos.write(len);
        }


        //服务器反馈结果
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(accept.getOutputStream()));
        bw.write("上传成功");
        bw.newLine();
        bw.flush();
        bw.close();
        ss.close();
    }
}
